/**
 * 
 * @authors Riche
 * @date    2016-07-05 10:39:22
 * @version 1.1.0
 */


var title = $.getUrlVar("s");
var forword = encodeURIComponent(window.location.href);
var backUrl = $.getUrlVar("back");

var info = new Vue({
  el:"#app",
  data:{
    scrollbar:{},
    data:[],
    isLoading:true,
    pageIndex :1,
    pageSize : PAGESIZE,
    addShow: false,
    keyWork:""
  },
  created:function(){
      var dtd = $.Deferred();
      var _self = this;
      //搜索列表
      title = decodeURIComponent(title);
      var data = {
          title: title,
          pageSize:_self.pageSize,
          pageIndex:_self.pageIndex
      };
      //data = Common.jsonEncode(data);
      _self.scrollbar = new scrollBar({
          isLoading: _self.isLoading,
          url: "look_getListByTypeID",
          type:"get",
          data:data
      });
      _self.loadlist();
      
      $("#searchword").val(title);
      $("#searchword2").val(title);
      _self.keyWork = title;
  },
  compiled:function(){
    var _self = this;
    $(document).scroll(function () {
      if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
          _self.loadlist(function(){
          });
      }
    }); 

  },
  methods:{
    loadlist:function(callback){
      var _self = this;
      _self.scrollbar.load(function(pageIndex,data){
        for(var i = 0; i < data.length; i++){
          _self.data.push(data[i]);
        }
        _self.pageIndex = pageIndex;
        if(_self.data.length==0){
          $(".searchNone").show();
        }
      },function(isLoading){
        _self.isLoading = isLoading;
        if(_self.data.length==0){
          $(".searchNone").show();
        }
      });
      
    },
    search:function(){
      var _self = this;
      var title = $("#searchword").val();
      if(title==""){
        alert("请输入关键字");
        return;
      }
      $("#searchword2").val(title);
      _self.keyWork = title;

      $("#header2,.cateBoxBg").hide();
      $("#header1").show();
      $(".searchNone").hide();
      _self.isLoading = true;
      _self.pageIndex = 1;
      _self.data=[];

      var data = {
          title: title,
          pageSize:_self.pageSize,
          pageIndex:_self.pageIndex
      };
      //data = Common.jsonEncode(data);
      _self.scrollbar = new scrollBar({
          isLoading: _self.isLoading,
          url: "look_getListByTypeID",
          type:"get",
          data:data
      });

      _self.loadlist();
      //失去焦点
      $("#aback").focus();

    },
    toartDetail:function(id){
      window.location.href = "articleDetail.html?id=" + id + "&back=" + forword;
    },
    back:function(){
      window.location.href = decodeURIComponent(backUrl);
    }

  },
  watch:{
    "data": function(){
    }
  }

});






